using System;
using Kassandra.Core;
using Kassandra.Core.Infrastructure.ResourceManagement;

namespace Kassandra.WindowsUI.Presenters
{
    public class OpenAndSavePresenter
    {
        private readonly IOpenAndSave _view;
        private readonly ProcessFile _process;

        public OpenAndSavePresenter(IOpenAndSave view)
        {
            _view = view;
            _process = new ProcessFile();
            _process.DisplayScreenMessage += EngineMessage;
        }

        public void EngineMessage(string message)
        {
            if (_view != null)
            {
                _view.DisplayMessage(message);
            }
        }

        public void AddNewImage(object sender, EventArgs e)
        {
            _view.AddNewImage();
        }

        public void Translate(object sender, EventArgs e)
        {
            try
            {
                if (_view.SourceFile.Length == 0 || _view.DestinationFile.Length ==0)
                {
                    _view.DisplayMessage(MessageManagement.For("PleaseEnterBothFiles"));
                    return;
                }
                _view.ShowProgress = true;
                _process.With(_view.SourceFile, _view.DestinationFile);
                _view.ShowProgress = false;
                _view.DisplayMessage(MessageManagement.For("ProcessingComplete"));
            }

            catch(Exception ex)
            {
                _view.DisplayMessage(ex.ToString());
            }
        }
    }
}